package com.zygh.lz.controller;

import com.google.gson.GsonBuilder;
import com.zygh.lz.entity.Problem;
import com.zygh.lz.service.ProblemService;
import com.zygh.lz.stapprove.ResultUtil;
import com.zygh.lz.stapprove.SysPcLog;
import com.zygh.lz.stapprove.ViLog;
import com.zygh.lz.vo.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Api(tags = "问题类", description = "ProblemController")
@RestController
public class ProblemController {
    @Autowired
    private ProblemService problemService;



    @ApiOperation("问题模块>按条件查询没有核查的问题")
    @GetMapping("selectProblem")
    public ResultBean selectProblem(Integer staffAcceptId, String roadName, String problemStrat) {
        return problemService.selectProblem(staffAcceptId, roadName, problemStrat);
    }

    @ApiOperation("删除问题")
    @GetMapping("delProblem")
    //@SysPcLog(module = "删除问题",operation = "删除")
    public ResultBean delProblem(Integer id) {
        return problemService.delProblem(id);
    }

    @ApiOperation("根据人查询全部问题")
    @GetMapping("selectProblemByStaffId")
    public ResultBean selectProblemByStaffId(Integer staffReportId) {
        return problemService.selectProblemByStaffId(staffReportId);
    }

    @GetMapping("selectProblemByRosove")
    public ResultBean selectProblemByRosove(Integer id, HttpServletRequest request) {
        return problemService.selectProblemByRosove(id);
    }

    @ApiOperation("根据道路类型查询问题")
    @GetMapping("selectAllByRoadType")
    public ResultBean selectAllByRoadType(Integer sysStaffId, String roadType, HttpServletRequest request) {
        return problemService.selectAllByRoadType(sysStaffId, roadType);
    }


    @ApiOperation("根据人查询问题")
    @GetMapping("selectDimStaff")
    public ResultBean selectDimStaff(Integer sysStaffId, String beginTime, String endTime, HttpServletRequest request) {
        return problemService.selectDimStaff(sysStaffId, beginTime, endTime);
    }

    @ApiOperation("领导管理的人所查询问题的模糊查询")
    @GetMapping("selectDimStaffOther")
    public ResultBean selectDimStaffOther(Integer staffId, String beginTime, String endTime, HttpServletRequest request) {
        return problemService.selectDimStaffOther(staffId, beginTime, endTime);
    }

    @GetMapping("selectDimAll")
    @ApiOperation("巡查记录个数统计")
    public ResultBean selectDimAll(String startTime, String endTime, HttpServletRequest request) {
        return problemService.selectDimAll(startTime, endTime);
    }

    @ApiOperation("巡查记录个数统计")
    @GetMapping("selectDimAllSy")
    public ResultBean selectDimAllSy() {
        return problemService.selectDimAllSy();
    }


    @ApiOperation("查询所有除去已完成以外的多有问题")
    @GetMapping("selectProblemByState")
    public ResultBean selectProblemByState() {
        return problemService.selectProblemByState();
    }




    @ApiOperation("查询所有不能解决的问题")
    @GetMapping("selectProbleByStart")
    public ResultBean selectProbleByStart(String problemState) {
        return problemService.selectProbleByStart(problemState);
    }

    @ApiOperation("模糊查询")
    @GetMapping("selectByProblemdetail")
    public ResultBean selectByProblemdetail(String typeKey, String problemStrat, String beginTime, String endTime, HttpServletRequest request) {
        return problemService.selectByProblemdetail(typeKey, problemStrat, beginTime, endTime);
    }

    @ApiOperation("批量删除")
    @GetMapping("deleteByProblemid")
    //@SysPcLog(module = "批量删除问题类",operation = "批量删除")
    public ResultBean deleteByProblemid(int[] array) {
        return problemService.deleteByProblemid(array);
    }

    @ApiOperation("问题模块>统计所有")
    @GetMapping("selectAllCount")
    public ResultBean selectAllCount(String sectionname) {
        return problemService.selectAllCount(sectionname);
    }

    @ApiOperation("待我审批模糊查询")
    @GetMapping("selectByObscure")
    public String selectByObscure(HttpServletResponse response, String solution, String type, String section, String startTime, String endTime) {
        //解决跨域问题
        response.setHeader("Access-Control-Allow-Origin", "*");
        List<Problem> problems = problemService.selectByObscure(solution, type, section, startTime, endTime);
        GsonBuilder gb = new GsonBuilder();
        gb.disableHtmlEscaping();
        //定义data用来接收使用gb.create().toJson将list转换为json的数据
        String data = gb.create().toJson(problems);
        return data;
    }

    @ApiOperation("根据接收人查询上报的问题")
    @GetMapping("findProblemByAccept")

    public ResultBean findProblemByAccept(Integer id,
                                          @RequestParam(defaultValue = "1") int pageNum,
                                          @RequestParam(defaultValue = "10") int pageSize) {
        return problemService.findProblemByAccept(id, pageNum, pageSize);
    }

    @ApiOperation("未读上报消息")
    @GetMapping("findProblemByIsRead")

    public ResultBean findProblemByIsRead(Integer id) {
        return problemService.findProblemByIsRead(id);
    }




    @ApiOperation("根据上报人查询上报的问题")
    @GetMapping("findProblemByAppear")
    public ResultBean findProblemByAppear(Integer id) {
        List<Map> problemByAppear = problemService.findProblemByAppear(id);
        return ResultUtil.setOK("success", problemByAppear);
    }

    @ApiOperation("抄送")
    @GetMapping("copyTo")
    public ResultBean copyTo(Integer problemId, Integer userId) {
        int problemByAppear = problemService.copyTo(problemId, userId);
        return ResultUtil.setOK("成功", problemByAppear);
    }



}
